package com.ethink.platform.controller.order;

import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.order.api.TocSaleImportJobLogFacade;
import com.ethink.order.api.info.TocSaleImportJobLogInfo;
import com.ethink.platform.controller.order.info.ExportInfo;
import com.ethink.platform.manager.ExportManager;
import com.ethink.platform.manager.TocSaleOrderManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 销售单批量导入job处理结果记录表 Controller
 *
 * @author default
 * @date 2022-12-20
 */
@Tag(name = "TocSaleImportJobLogController", description = "销售单批量导入job处理结果记录表 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/system-service")
public class TocSaleImportJobLogController extends BaseController {

    @Autowired
    private TocSaleImportJobLogFacade tocSaleImportJobLogFacade;

    @Autowired
    private TocSaleOrderManager tocSaleOrderManager;

    @Autowired
    private ExportManager exportManager;


    @Operation(summary = "处理结果查询")
    @GetMapping("/tocSaleImportJobLog/query/{logId}")
    public CommonResponse<List<TocSaleImportJobLogInfo>> queryLogByLogId(@PathVariable("logId") Long logId) {
        return succeedWith(tocSaleImportJobLogFacade.queryLogByLogId(logId));
    }

    @Operation(summary = "记录处理")
    @PostMapping("/tocSaleImportJobLog/process/{id}")
    public CommonResponse processTocSaleImportJobLog(@PathVariable Long id) {
        tocSaleOrderManager.processTocSaleImportJobLog(id);
        return succeed();
    }

    @Operation(summary = "失败原因日志导出")
    @PostMapping("/tocSaleImportJobLog/exportReasonFailureLog/{logId}")
    public CommonResponse<ExportInfo> reasonFailureLogExport(@PathVariable(name = "logId") Integer logId) {
        return succeedWith(exportManager.exportReasonFailureLog(logId));
    }

}